<?php


namespace app\common\service;


use app\common\model\MemberBalance;
use app\common\model\Members as MemberModel;
class Balance
{
    //用户余额重算                    //用户id
    static public function retryBalance($user_id){
        $data = MemberModel::get($user_id);
        $balance = MemberBalance::where("userid",$user_id)->sum('balance');
        $data->balance = $balance;
        if ($data->save())
            return true;
        return false;
    }
    //写入用户余额记录                      //用户id   金额   类型 1提现 0佣金分红 店铺id        订单id
    static public function saveBalanceLog($user_id,$balance,$type,$remark,$business_id=0,$order_id=0){
        $data = MemberBalance::create([
            'userid'  => $user_id,
            'balance' => $balance,
            'type'  => $type,
            'remark'=> $remark,
            'business' => $business_id,
            'order_id' => $order_id
        ]);
        if ($data->id)
            return true;
        return false;
    }
}